<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$allitemgame=$this->allitemgame;
if($_RQ['op']=='main'){
	if(!$_RQ['id']){
		exi('请选择模板！','error');
	}
	$this->session('tpl_id',$_RQ['id']);
	$return['item']=pdo_get('jy_merch_game_item_tpl',array('id'=>$_RQ['id']));
    $return['item']['logo']=tomedia($return['item']['logo']);
	$return['item']['rest_time']=model('jy_weishop/model')->date(7*24*3600);
	$return['item']['goods']=json_decode($return['item']['goods'],true);
	$return['item']['typename']=$allitemgame[$return['item']['gamename']]['title'];
	$return['item']['unitname']=$allitemgame[$return['item']['gamename']]['unit'];
	$params=array('pid'=>0);
	$return['params']=$params;
	$return['p_group']=pdo_getall('jy_merch_category',array('uniacid'=>$_SESSION['uniacid']),array('id','catename'));
	$return['lognum']=pdo_count('jy_merch_game_order',array('uniacid'=>$_SESSION['uniacid']),'id');
	$return['msgnum']=pdo_count('jy_merch_game_item_msg',array('uniacid'=>$_SESSION['uniacid']),'id');
	set_html('title','模板预览');
	exi($return);
}
if($_RQ['op']=='check_up'){
	$pid=$_RQ['pid']?intval($_RQ['pid']):$_SESSION['pid'];
	if(!$pid){
		exi('请选择模板！','error');
	}
	//$this->model('member')->check_up($pid);
	exi('','','jy_quanhuo/upitem//pid='.$pid);
}
if($_RQ['op']=='getlog'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['gamename']){
		$params['gamename']=$_RQ['gamename'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 30;
	$list=pdo_getslice('jy_merch_game_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$lasttime=TIMESTAMP-$item['createtime'];
			$item['lasttime']=$lasttime;
			if($lasttime>24*3600){
				$item['days']=intval($lasttime/(24*3600)).'天前';
			}elseif($lasttime>=3600){
				$item['days']=intval($lasttime/3600).'小时前';
			}else{
				$item['days']=intval($lasttime/60).'分钟前';
			}
			$item['createtime']=date('Y-m-d',$item['createtime']);
			$item['member'] = pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
			$item['member']['avatar']=tomedia($item['member']['avatar']);
		}
	}	
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='getmsg'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['gamename']){
		$params['gamename']=$_RQ['gamename'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_merch_game_item_msg',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$lasttime=TIMESTAMP-$item['createtime'];
			$item['lasttime']=$lasttime;
			if($lasttime>24*3600){
				$item['days']=intval($lasttime/(24*3600)).'天前';
			}elseif($lasttime>=3600){
				$item['days']=intval($lasttime/3600).'小时前';
			}else{
				$item['days']=intval($lasttime/60).'分钟前';
			}
			$item['createtime']=date('Y-m-d',$item['createtime']);
			$item['member'] = pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
			$item['member']['avatar']=tomedia($item['member']['avatar']);
		}
	}	
	$return['list']=$list;
	exi($return);
}